<template>
  <div class="container">
    <div class="app-container" style="padding: 20px;">
      <el-row style="display: flex; border-bottom: 1px solid #ccc;">
        <span style="margin-top: 20px;">楼宇名称</span>
        <el-input v-model="add.name" placeholder="请输入楼宇名称" style="margin-top: 10px;margin-bottom: 10px; margin-left: 20px; width: 200px;" />
        <el-button type="primary" size="mini" style="height: 40px; margin-top: 10px; margin-bottom: 20px; margin-left: 20px; width: 65px; border-radius: 10px  ;" @click="getList">查询</el-button>
      </el-row>
      <el-row style="margin-top: 10px;">
        <el-button type="primary" size="mini" style="border-radius: 5px" @click="addBuilding">添加楼宇</el-button>
      </el-row>
      <el-table :data="list">
        <el-table-column label="序号" type="index" />
        <el-table-column label="楼宇名称" prop="name" />
        <el-table-column label="层数" prop="floors" />
        <el-table-column label="在管面积" prop="area" />
        <el-table-column label="物业费" prop="propertyFeePrice" />
        <el-table-column label="状态" prop="status">
          <template v-slot="{row}">
            <span> {{ row.status===0? "空置中":row.status===1?"租赁中":'无' }} </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" prop="demoFlag">
          <template v-slot="{row}">
            <!-- <el-button size="mini" type="text">分配权限</el-button> -->
            <el-button size="mini" type="edit" @click="editRole(row.id)">编辑</el-button>
            <el-button size="mini" type="del" @click="deleteRole(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row type="flex" justify="end">
        <el-pagination
          layout="prev, pager, next , jumper , total"
          :total="add.total"
          :page-size="add.pageSize"
          :current-page="add.page"
          @current-change="changePage"
        />
      </el-row>
    </div>
    <Building ref="addDept" :show-dialog.sync=" showDialog" @updateDept="getFloor" />
  </div>
</template>
<script>
import { getFloorAPI, deleteFloorAPI } from '@/api'
import { Building } from './components'
export default {
  name: 'Attendance',
  components: {
    Building
  },
  data() {
    return {
      showDialog: false,
      list: [],
      obj: [{
        name: '',
        floors: '',
        area: '',
        propertyFeePrice: ''
      }],
      add: {
        total: 0,
        name: '',
        pageSize: 10,
        page: 1
      }
    }
  },
  created() {
    this.getFloor()
  },
  methods: {
    async getFloor() {
      const { rows, total } = await getFloorAPI(this.add)
      this.list = rows
      this.add.total = total
    },
    addBuilding() {
      this.showDialog = true
    },
    changePage(newpage) {
      this.add.page = newpage
      this.getFloor()
    },
    editRole(id) {
      this.currentNodeId = id
      this.showDialog = true
      this.$refs.addDept.getFloor(id)
    },
    deleteRole(id) {
      deleteFloorAPI(id)
      this.getFloor()
    },
    async getList() {
      await this.getFloor()
    }
  }
}
</script>
